<html>

<head>
</head>

<?
//********** Old system*************
/*
<p>
<applet code="loadCAS.class" width=600 height=550
        archive='./cas_system/module_class/cas_library.jar'>

        <param name='title' value="<? echo base64_decode($title); ?>"/>
        <param name='user'  value="<? echo $email_usuario; ?>"/>
        <param name='param' value="<? echo base64_decode($param); ?>"/>
        <param name='netAddr' value="<? echo $REMOTE_ADDR; ?>"/>
</applet>

</p>
<b>This Applet requires Java 1.4.x or higher. </b><br>
Click <b><a href="http://www.sun.com/download/index.jsp?cat=Java%20%26%20Technologies&tab=3&subcat=Java">here</a></b> to download Java Plug-in or try to find it made for your browser.<p></p>
*/
?>
<?
    include("config.php");
    $param = explode("[.e.]",base64_decode($param));
    $descriptorspec = array(
        0 => array("pipe", "r"),
        1 => array("pipe", "w"),
        2 => array("file", $DOCUMENT_ROOT."/error-scilab-output.txt", "a")
    );

    $env = array('HOME' => $DOCUMENT_ROOT,'DISPLAY' => '0');

    $process = proc_open('scilab -nogui', $descriptorspec, $pipes, $cwd, $env);
    if (is_resource($process)) {
        $str1 = array("%","'");
        $str2 = array("\%","''");
        for ($i=1; $i<count($param);$i++)
            fwrite($pipes[0], "printf(' ".str_replace($str1,$str2,$param[$i])."\\n');".$param[$i]."\n");
        fwrite($pipes[0],"exit\n");
        fclose($pipes[0]);
        echo "<pre>\n";	
        echo stream_get_contents($pipes[1]);
        echo "\n</pre>\n";
        fclose($pipes[1]);
        $return_value = proc_close($process);
    }
?>
</body>
</html>
